/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package im.subscriptionpackage;

import im.numgenerator.PseudoRandomGenerator;
import java.util.List;

/**
 *
 * @author Giovanni
 */
public class SubscriptionGenerator {

    PseudoRandomGenerator prg;

    public SubscriptionGenerator(PseudoRandomGenerator prg ) {
        this.prg = prg;
    }

    public TopicSubscription generateTopicSubscription(String keywords) {

        TopicSubscription sub = new TopicSubscription(keywords);
        return sub;
    }
//"name == "+(String) topics.get(rTopics)+" or " +"value =="+objects.get(rObjects).toString()

    public ContentSubscription generateContentSubscription(String criteria) {

        ContentSubscription sub = new ContentSubscription(criteria);
        return sub;
    }

    public TypeSubscription generateTypeSubscription(Object type, String hierarchy) {

        TypeSubscription sub = new TypeSubscription(type.getClass(), hierarchy);
        return sub;
    }

    public Subscription generateSubscription(List types, List topics, List objects, String hierarchy) {

        Subscription sub = null;

        int sizeTypes = types.size();
        int sizeTopics = topics.size();
        int sizeObjects = objects.size();

        int rTypes = (int) (prg.getUniform() * sizeTypes);
        int rTopics = (int) (prg.getUniform() * sizeTopics);
        int rObjects = (int) (prg.getUniform() * sizeObjects);

        double cond = prg.getUniform();
        if (cond < 0.33) {
            String tp = (String) topics.get(rTopics);
            sub = generateTopicSubscription(tp);


        //System.out.println(sub.getClass().toString()+"-"+tp);
        }
        if (cond > 0.33 && cond < 0.66) {
            String cn = "name == " + (String) topics.get(rTopics) + " and " + "value == " + objects.get(rObjects).toString();

            sub = generateContentSubscription(cn);
        // System.out.println(sub.getClass().toString()+"-"+cn);

        }
        if (cond > 0.66) {
            Object ty = types.get(rTypes);

            sub = generateTypeSubscription(ty, hierarchy);
        // System.out.println(sub.getClass().toString()+"-"+ty+"-"+hierarchy);

        }


        return sub;
    }
}
